package com.juc.completionService.completionService4;

import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Run2 {

	public static void main(String[] args) throws InterruptedException, ExecutionException {
		MyCallableA callableA = new MyCallableA();
		MyCallableB callableB = new MyCallableB();
		ExecutorService executorService = Executors.newCachedThreadPool();
		CompletionService csRef = new ExecutorCompletionService<>(executorService);
		csRef.submit(callableA);
		csRef.submit(callableB);
		for (int i = 0; i < 2; i++) {
			System.out.println("zzzzzzzzzzzzzzzzz  " + csRef.poll(6, TimeUnit.SECONDS).get());
		    System.out.println("X");
		}
		System.out.println("main end!");
	}
}
